/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vue;

import Modele.Grille;
import java.awt.Color;
import java.util.Observable;
import java.util.Observer;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

/**
 *
 * @author p0902486
 */
public class Case extends JPanel implements Observer {

    int[] coord;

    public Case(int num, int x, int y) {
        super();
        build(num, x, y);
    }

    public void build(int num, int x, int y) {
        colorerCase(num);
        this.coord = new int[2];
        this.setCoordCase(x, y);
    }

    public void setCoordCase(int x, int y) {
        this.coord[0] = x;
        this.coord[1] = y;
    }

    public void colorerCase(int num) {
        Border bordure = new BevelBorder(BevelBorder.RAISED);
        switch (num) {
            case 0:
                this.setBackground(null);

                this.setBorder(BorderFactory.createEmptyBorder());
                break;
            case 1:
                this.setBackground(Color.BLUE);
                this.setBorder(bordure);
                break;
            case 2:
                this.setBackground(Color.RED);
                this.setBorder(bordure);
                break;
            case 3:
                this.setBackground(Color.GREEN);
                this.setBorder(bordure);
                break;
            case 4:
                this.setBackground(Color.CYAN);
                this.setBorder(bordure);
                break;
            case 5:
                this.setBackground(Color.MAGENTA);
                this.setBorder(bordure);
                break;
            case 6:
                this.setBackground(Color.WHITE);
                this.setBorder(bordure);
                break;
            case 7:
                this.setBackground(Color.DARK_GRAY);
                this.setBorder(bordure);
                break;
            default:
                this.setBackground(Color.ORANGE);
                this.setBorder(bordure);
                break;
        }
    }

    public void update(Observable obs, Object arg) {

        if (obs instanceof Grille) {
            int[] coords = (int[]) arg;
            if (coords[0] == this.coord[0] && coords[1] == this.coord[1]) {
                this.colorerCase(coords[2]);

               // Border blackline = BorderFactory.createLineBorder(Color.orange,1);
                // this.setBorder(blackline);
            }
        }
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
